package com.magictower.primary.activity;

import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.magictower.primary.R;
import com.magictower.primary.fragment.LockFragment;
import com.magictower.primary.fragment.UnLockFragment;

/**
 * @author kejunzhan
 * @since 2017/12/20
 */

public class AppLockActivity extends AppCompatActivity implements View.OnClickListener{

    private TextView unlock;
    private TextView lock;
    private LockFragment lockFragment;
    private UnLockFragment unlockFragment;
    private FragmentManager manager;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initUI();
    }

    private void initUI() {
        setContentView(R.layout.activity_app_lock);
        unlock = (TextView) findViewById(R.id.tv_unlock);
        lock = (TextView) findViewById(R.id.tv_lock);
        unlock.setOnClickListener(this);
        lock.setOnClickListener(this);

        lockFragment = new LockFragment();
        unlockFragment = new UnLockFragment();
        manager = getFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.replace(R.id.fl_frame, unlockFragment).commit();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        FragmentTransaction transaction = manager.beginTransaction();
        switch (v.getId()) {
            case R.id.tv_unlock:
                //未加锁
                unlock.setBackgroundResource(R.drawable.tab_left_pressed);
                lock.setBackgroundResource(R.drawable.tab_right_default);
                transaction.replace(R.id.fl_frame, unlockFragment).commit();
                break;
            case R.id.tv_lock:
                //加锁
                unlock.setBackgroundResource(R.drawable.tab_left_default);
                lock.setBackgroundResource(R.drawable.tab_right_pressed);
                transaction.replace(R.id.fl_frame, lockFragment).commit();
                break;
        }
    }
}
